/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.afraid.poison.db2php.nb;

import java.io.File;
import javax.swing.JFileChooser;
import javax.swing.JPanel;
import javax.swing.filechooser.FileFilter;
import org.afraid.poison.db2php.generator.xml.Connection;
import org.openide.util.Exceptions;

public final class PhpClassesFromXmlVisualPanel1 extends JPanel {

	public static class FileFilterDb2Php extends FileFilter {

		@Override
		public boolean accept(File f) {
			if (f.isDirectory()) {
				return true;
			}
			if (f.getName().endsWith(".xml")||f.getName().endsWith(".db2php")) {
				if (f.length()>1024*1024) {
					return false;
				}
				try {
					return !Connection.fromXMLFile(f).isEmpty();

				} catch (Exception e) {
					Exceptions.printStackTrace(e);
				}
			}
			return false;
		}

		@Override
		public String getDescription() {
			return "Valid db2php XML control files";
		}
	}

	/** Creates new form PhpClassesFromXmlVisualPanel1 */
	public PhpClassesFromXmlVisualPanel1() {
		initComponents();
	}

	@Override
	public String getName() {
		return "Choose XML control file";
	}

	public JFileChooser getXmlFileChooser() {
		return xmlFileChooser;
	}

	/** This method is called from within the constructor to
	 * initialize the form.
	 * WARNING: Do NOT modify this code. The content of this method is
	 * always regenerated by the Form Editor.
	 */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        xmlFileChooser = new javax.swing.JFileChooser();

        xmlFileChooser.setBackground(javax.swing.UIManager.getDefaults().getColor("Nb.Desktop.background"));
        xmlFileChooser.setControlButtonsAreShown(false);
        xmlFileChooser.setFileFilter(new FileFilterDb2Php());

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(xmlFileChooser, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(xmlFileChooser, javax.swing.GroupLayout.DEFAULT_SIZE, 390, Short.MAX_VALUE)
                .addContainerGap())
        );
    }// </editor-fold>//GEN-END:initComponents
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JFileChooser xmlFileChooser;
    // End of variables declaration//GEN-END:variables
}
